package com.cws.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.cws.business.IUserBusiness;
import com.cws.dao.QuerySupport;
import com.cws.model.User;
import com.cws.web.ReponseData;


@Controller
public class UserController extends BaseController{
	
	@Autowired
	private IUserBusiness userBusiness;
	
	
	 @RequestMapping("/registerPage")
     public ModelAndView Login(HttpServletRequest request){
		 ModelAndView mv = new ModelAndView("jsp/user/register");
         return mv;
     }
	 
	 @ResponseBody
	 @RequestMapping(value="/ajax/register")//@ModelAttribute he 
	 public Map<String, Object> register(HttpServletRequest request,@ModelAttribute("registerForm")User user) {
		Map<String, Object> modelMap = new HashMap<String, Object>();
		boolean status =  userBusiness.saveUser(user);
		modelMap.put("status",status);//
		modelMap.put("data", user);
		return modelMap;
	 }
	 
	 @ResponseBody
	 @RequestMapping(value="/ajax/listUser")//@ModelAttribute he 
	 public ReponseData listUser(HttpServletRequest request) {
		 Map params = new HashMap();
		 params.put(QuerySupport.PARAM_TABLENAME, User.class);
		 List users =  userBusiness.getUsers(params);
		
		 return ReponseData.createSuccess(users);
	 }
	
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
}
